const express = require('express')
const router = express.Router();
const { residentController } = require('../contorller/SunXuDong/residentController')
router.get('/test1', (req, res) => {
    // console.log(req.query);
    res.send({ message: '成功！' })
})
router.get('/getResidentInfo', residentController.getAllResidentInfo)
router.post('/getHealthRecordById', residentController.getHealthRecordById)
router.post('/getAllHealthRecordById', residentController.getAllHealthRecordById)
router.post('/deleteData', residentController.deleteData)

router.post('/resident', (req, res) => {
    console.log(req.body);
    const resnum = { data: [280, 300, 250, 230, 180, 210, 270] }
    const signum = { data: [130, 100, 180, 130, 150, 100, 80] }
    const sernum = { data: [100, 130, 200, 180, 295, 160, 180] }
    const resnumTotal = resnum.data.reduce((pre, cur) => {
        return pre + cur
    }, 0)
    const signumTotal = signum.data.reduce((pre, cur) => {
        return pre + cur
    }, 0)
    const sernumTotal = sernum.data.reduce((pre, cur) => {
        return pre + cur
    }, 0)
    if (req.body.type === 'resnum') {//居民数量
        res.send(resnum)
    } else if (req.body.type === 'signum') {//签约量
        res.send(signum)
    } else if (req.body.type === 'sernum') {//服务量
        res.send(sernum)
    } else if (req.body.type === 'total') {//总量
        res.send({ data: { resnumTotal, signumTotal, sernumTotal } })
    } else {
        res.status(404)
        res.send('资源未找到！请检查参数是否正确')
    }
})
module.exports = router;